var mysql = require("mysql");
var config = require("../config/index");
module.exports = {
    install: async app => {
        app.use((req, res, next) => {
            req.db = (str) => {
                return new Promise((reslove, reject) => {
                    var connection = mysql.createConnection(config.mysql);
                    connection.connect()
                    console.log(str)
                    connection.query(str, (err, rows, fields) => {
                        if (err) throw err
                        reslove(rows);
                    })
                    connection.end()
                })
            }
            next()
        });
        return
    }
}